package com.topnav.mc.admin.entity.enums;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author: kenny
 * @Date: 2023/11/13 11:45
 */
public enum FencePolygonType {

    POLYGON(1,"多边形"),
    CIRCLE(2,"园形"),
    RECT(3,"矩形"),
    SQUARE(4,"正方形"),
    STAR(5,"星形");


    private int code;
    private String desc;

    private FencePolygonType(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public int getCode() {return code;}

    public void setCode(int code) {this.code = code;	}

    public String getDesc() {return desc;}

    public void setDesc(String desc) {this.desc = desc;}

    public static List<EnumModal> toList(){
        List<EnumModal> list = new ArrayList<>();
        for (FencePolygonType enumEntity : FencePolygonType.values()) {
            EnumModal enumModal = new EnumModal();
            enumModal.setIndex(enumEntity.ordinal());
            enumModal.setCode(enumEntity.getCode());
            enumModal.setName(enumEntity.name());
            enumModal.setDesc(enumEntity.getDesc());
            list.add(enumModal);
        }
        return list;
    }

    public static FencePolygonType getByCode(int code) {
        for (FencePolygonType fencePolygonType : FencePolygonType.values()) {
            if (fencePolygonType.getCode() == code) {
                return fencePolygonType;
            }

        }
        return null;
    }

    public static String getDescByCode(int code) {
        FencePolygonType fencePolygonType = getByCode(code);
        if (fencePolygonType != null){
            return fencePolygonType.getDesc();
        }
        return null;
    }

}
